<template>
  <div class="center">
    <!-- 头部 -->
    <div class="table_header flex flex_bet flex-wrap">
      <div class="table_button">
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="Refresh"></el-button>
        <el-button v-permission="['超级管理员']" type="primary" icon="el-icon-document-copy" size="mini" @click="batchEditVisible = true">批量正式激活</el-button>
        <el-button v-permission="['超级管理员']" type="primary" icon="el-icon-document-copy" size="mini" @click="batchResetVisible = true">批量重置QID</el-button>
        <el-button v-permission="['超级管理员']" type="primary" icon="el-icon-document-copy" size="mini" @click="batchCreateVisible = true">批量生成qid</el-button>
        <el-button type="primary" icon="el-icon-upload2" size="mini" @click="exportFormVisible = true">导出</el-button>
        <el-button type="primary" icon="el-icon-upload2" size="mini" @click="downLoadData">下载筛选</el-button>

        <el-button type="primary" size="mini" @click="handleDownload">批量正式激活和重置模板<i class="el-icon-paperclip el-icon--right"></i></el-button>
      </div>
      <div class="table_searchs flex felx_align">
        <div class="table_search flex">
          <el-input placeholder="搜索" v-model="searchTable" class="input-with-select" size="small">
            <el-select v-model="select" slot="prepend" placeholder="请选择" class="table_select" style="width:105px">
              <el-option label="SN" value="1"></el-option>
              <el-option label="QID" value="2"></el-option>
              <el-option label="UID" value="3"></el-option>
              <el-option label="归属" value="4"></el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search" @click="idnameSearch"></el-button>
          </el-input>
        </div>
        <dynamicTable :checkboxVal="checkboxVal" @alter="alterCheckbok"/>
      </div>
    </div>
    <el-table stripe style="width: 100%"  border :fit="true"  highlight-current-row ref="tableDataRef" :data="tableData" :key="key">
      <el-table-column v-if="colData[0].istrue"  align="center" prop="id" label="ID" fixed width="40" ></el-table-column>
      <el-table-column v-if="colData[1].istrue"  align="center" prop="sn" label="SN" fixed width="120"></el-table-column>
      <el-table-column v-if="colData[2].istrue"  align="center" prop="qid" label="QID" fixed width="120"></el-table-column>
      <el-table-column v-if="colData[3].istrue"  align="center" prop="uid" label="UID" fixed width="80"></el-table-column>
      <el-table-column v-if="colData[4].istrue"  align="center" prop="status" label="状态"></el-table-column>
      <el-table-column v-if="colData[5].istrue"  align="center" prop="platter" label="套餐"></el-table-column>
      <el-table-column v-if="isAdmin"  align="center" prop="expire_time" label="授权到期日期" width="140">
        <template slot-scope="scope">{{scope.row.expire_time| newDate}}</template>
      </el-table-column>
      <el-table-column v-if="isAdmin"  align="center" prop="custom_valid_days" label="代理商授权有效期" width="140">
        <template slot-scope="scope">
          <div v-if="scope.row.custom_valid_days==0">
            <span>未设置</span>
          </div>
          <div v-else>
            <span>{{scope.row.custom_end_time}}</span>
          </div>
         </template>
      </el-table-column>
      <el-table-column  align="center" prop="custom_valid_days" label="学校授权有效期" width="140">
        <template slot-scope="scope">
          <div v-if="scope.row.school_valid_days==0">
            <span>未设置</span>
          </div>
          <div v-else>
            <p>{{scope.row.school_end_time}}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column v-if="colData[7].istrue"  min-width="110px" align="center" prop="is_qid" label="可生成qid"></el-table-column>
      <el-table-column v-if="colData[8].istrue"  align="center" prop="admin_name" label="归属"></el-table-column>
      <el-table-column v-if="colData[9].istrue" min-width="100px" align="center" prop="batch" label="批次"></el-table-column>
      <el-table-column v-if="colData[10].istrue"  align="center" prop="sn_type" label="设备类别"></el-table-column>
      <el-table-column v-if="colData[11].istrue"  align="center" prop="create_time" label="生成时间" width="140">
        <template slot-scope="scope">{{scope.row.create_time| newDate}}</template>
      </el-table-column>
      <el-table-column v-if="colData[12].istrue"  align="center" prop="display_identity_switch" label="身份开关">
        <template slot-scope="scope">{{scope.row.display_identity_switch == 1 ? "显示" : "隐藏"}}</template>
      </el-table-column>
      <el-table-column   align="center" prop="is_teacher" label="身份">
        <template slot-scope="scope">{{scope.row.is_teacher == 1 ? "老师" : "学生"}}</template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-row>
            <el-button size="mini" type="primary" @click="toEdit(scope.row)">编辑</el-button>
            <el-button v-permission="['超级管理员']" size="mini" type="primary" @click="setRestId(scope.row.id)">重置</el-button>
            <el-popover placement="left" width="250" trigger="click">
              <el-button type="text" size="mini" @click="setPauseActiveId(scope.row.id)">暂停激活</el-button>
              <el-button v-permission="['超级管理员']" size="mini" type="text" @click="setActiveId(scope.row.id)">正式激活</el-button>
              <el-button v-permission="['超级管理员']" size="mini" type="text" @click="toAfterSale(scope.row.id)">售后换新</el-button>
              <el-button size="mini" type="text" @click="goToGanKao(scope.row.uid)">学情</el-button>
              <el-button slot="reference" size="mini">更多</el-button>
            </el-popover>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="paging">
      <el-pagination :current-page.sync="listQuery.startSize" background @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 50, 100, 200]" layout="total, sizes, prev, pager, next, jumper" :total="total" :page-size="listQuery.pageSize">
      </el-pagination>
    </div>

    <el-dialog  title="批量正式激活" :visible.sync="batchEditVisible" @close="batchEditClose" :close-on-click-modal="false" :close-on-press-escape="false" width="35%">
      <el-form :model="batchEditForm">
        <el-form-item label="导入文件" label-width="130px" class="snElsx">
          <div>
            <el-input autocomplete="off" placeholder="请点击上传，上传xls或xlsx文件" v-model="batchEditForm.pathname"></el-input>
            <upload-excel-component class="flex"  :before-upload="batchEditUpload" :loading="!videoFlag" @submitXlsx="submitBatchEditXlsx">
              <span>{{videoFlag ? '' : goodsData + '%'}}</span>
            </upload-excel-component>
          </div>
        </el-form-item>
        <div v-if="batchShow">
          <el-form-item label="成功:" label-width="130px" style="margin-bottom:0">共{{ snData.succeed}}条</el-form-item>
          <el-form-item label="失败:" label-width="130px" style="margin-bottom:0"> 共{{ snData.sameData}}条
            {{ this.snData.same.length >= 1 ? `( 位于:第${this.snData.same.toString()}行 ), 只展示前10行` : ''}}
          </el-form-item>
          <el-form-item label="总条数:" label-width="130px" style="margin-bottom:0">共{{snData.all}}条</el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="batchEditVisible = false" size="mini" round>取 消</el-button>
        <el-button type="primary" @click="batchEditVisible = false" size="mini" round>确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog  title="批量重置QID" :visible.sync="batchResetVisible" @close="batchRestClose" :close-on-click-modal="false" :close-on-press-escape="false" width="35%">
      <el-form :model="batchRestForm">
        <el-form-item label="导入文件" label-width="130px" class="snElsx">
          <div>
            <el-input autocomplete="off" placeholder="请点击上传，上传xls或xlsx文件" v-model="batchRestForm.pathname"></el-input>
            <upload-excel-component class="flex"  :before-upload="batchRestUpload" :loading="!videoFlag" @submitXlsx="submitBatchRestXlsx">
              <span>{{videoFlag ? '' : goodsData + '%'}}</span>
            </upload-excel-component>
          </div>
        </el-form-item>
        <div v-if="batchShow">
          <el-form-item label="成功:" label-width="130px" style="margin-bottom:0">共{{ snData.succeed}}条</el-form-item>
          <el-form-item label="失败:" label-width="130px" style="margin-bottom:0"> 共{{ snData.sameData}}条
            {{ this.snData.same.length >= 1 ? `( 位于:第${this.snData.same.toString()}行 ), 只展示前10行` : ''}}
          </el-form-item>
          <el-form-item label="总条数:" label-width="130px" style="margin-bottom:0">共{{snData.all}}条</el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="batchResetVisible = false" size="mini" round>取 消</el-button>
        <el-button type="primary" @click="batchResetVisible = false" size="mini" round>确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog  title="批量生成QID" :visible.sync="batchCreateVisible" @close="batchCreateClose" :close-on-click-modal="false" :close-on-press-escape="false" width="35%">
      <el-form :model="batchCreateForm">
        <el-form-item label="导入文件" label-width="130px" class="snElsx">
          <div>
            <el-input autocomplete="off" placeholder="请点击上传，上传xls或xlsx文件" v-model="batchCreateForm.pathname"></el-input>
            <upload-excel-component class="flex"  :before-upload="batchCreateUpload" :loading="!videoFlag" @submitXlsx="submitBatchCreateXlsx">
              <span>{{videoFlag ? '' : goodsData + '%'}}</span>
            </upload-excel-component>
          </div>
        </el-form-item>
        <div v-if="batchShow">
          <el-form-item label="成功:" label-width="130px" style="margin-bottom:0">共{{ snData.succeed}}条</el-form-item>
          <el-form-item label="失败:" label-width="130px" style="margin-bottom:0"> 共{{ snData.sameData}}条
            {{ this.snData.same.length >= 1 ? `( 位于:第${this.snData.same.toString()}行 ), 只展示前10行` : ''}}
          </el-form-item>
          <el-form-item label="总条数:" label-width="130px" style="margin-bottom:0">共{{snData.all}}条</el-form-item>
          <el-form-item label="本次申领记录:" label-width="130px" >
            <el-link type="primary" @click="downLoadExcelUl(snData.excelUrl)">点击下载</el-link>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="batchCreateVisible = false" size="mini" round>取 消</el-button>
        <el-button type="primary" @click="batchCreateVisible = false" size="mini" round>确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="SN码导出" :visible.sync="exportFormVisible" :close-on-click-modal="false" @close="exportFormClose" :close-on-press-escape="false" width="35%">
      <el-form :model="exportForm">
        <el-form-item label="导出类型:" label-width="130px">
          <el-select v-model="exportForm.type" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="exportFormVisible = false" size="mini" round>取 消</el-button>
        <el-button type="primary" @click="getDownloadSn" size="mini" round>确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="编辑" :visible.sync="editFormVisible" :close-on-click-modal="false" @close="editFormClose" :close-on-press-escape="false" width="35%">
      <el-form :model="editForm">
        <el-form-item label="身份切换开关:" label-width="160px">
          <el-radio-group v-model="editForm.display_identity_switch" :disabled="disableEdit">
            <el-radio :label="-1">隐藏</el-radio>
            <el-radio :label="1">显示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="学生个人信息编辑权限:" label-width="160px">
          <el-radio-group v-model="editForm.edit_permission" :disabled="disableEdit">
            <el-radio :label="-1">不可编辑</el-radio>
            <el-radio :label="1">可编辑</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="自定义授权有效期:" label-width="160px" prop="firstActiveTime">
          <el-input v-model="editForm.valid_days" style="width: 100px" type="number" min="0"></el-input>&nbsp;天
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editFormVisible = false" size="mini" round>取 消</el-button>
        <el-button type="primary" @click="edit()" size="mini" round>确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="售后换新" :visible.sync="afterSaleVisible" :close-on-click-modal="false" @close="afterSaleFormClose" :close-on-press-escape="false" width="35%">
      <el-form :model="afterSaleForm" :rules="rules" ref="ruleForm">
        <el-form-item label="QID:" label-width="130px" prop="qid">
          <el-input  placeholder="请输入旧机QID" v-model="afterSaleForm.qid"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="afterSaleVisible = false" size="mini" round>取 消</el-button>
        <el-button type="primary" @click="afterSaleSet('ruleForm')" size="mini" round>确 定</el-button>
      </div>
    </el-dialog>
    <delete-Dialog title="重置" :visible.sync="resetDialogs.show" width="25%" top="40vh" @deleteEvents="reset" :deleteText="resetDialogs.deleteText" :showDeleteText="false" />
    <delete-Dialog title="正式激活" :visible.sync="activeDialogs.show" width="25%" top="40vh" @deleteEvents="officialActive" :deleteText="activeDialogs.deleteText" :showDeleteText="false" />
    <delete-Dialog title="暂停激活" :visible.sync="pauseDialogs.show" width="25%" top="40vh" @deleteEvents="pauseActive" :deleteText="pauseDialogs.deleteText" :showDeleteText="false" />

    <div v-if="reportVisible" class="modal">
      <div class="modal-content">
        <span @click="reportVisible = false" class="close">&times;</span>
        <iframe :src="reportUrl" width="100%" height="100%" frameborder="0"></iframe>
      </div>
    </div>
  </div>
</template>

<script>
  import objectable from "@/utils/objectable.js";
  import dynamicTable from "@/components/DynamicTable";
  import deleteDialog from "@/components/deleteDialog";
  import tableMini from '@/utils/tableMini.js'
  import {
    activeQidControl, afterSaleQidControl,
    batchActiveQidControl, batchCreateQid,
    batchResetQidControl, downloadQueryData, downLoadSNQidControl, editQidControl, loginGanKaoH5, pauseActiveControl,
    queryQidControl,
    resetQidControl
  } from "@/api/qid";
  import forbid from "@/directive/permission/forbid";
  import {mapState} from "vuex";
  import permission from "@/directive/permission";
  import UploadExcelComponent from "@/components/UploadExcelSn/index";
  import snDialog from "@/components/snDialog/index";
  import battery from "@/components/electric/index";
  import WebsocketSn from "@/views/equipment/sn/components/websocketSn";
  import sninfoDetails from "@/views/equipment/sn/components/sninfoDetails";
  import {Loading} from "element-ui";
  export default {
    mixins: [tableMini],
    directives: { permission },
    components: { UploadExcelComponent, dynamicTable, snDialog, battery, deleteDialog, WebsocketSn, sninfoDetails },
    data() {
      return {
        key: 1,
        colData: [], //动态控制table
        checkboxVal: ["ID", "SN", "QID", "UID", "状态", "套餐", "授权到期日期", "归属", "批次", "设备类别", "是否可生成qid", "归属", "批次", "设备类别", "生成时间", "身份"],
        searchTable: "",
        select: "", //搜索条件
        tableData: [],
        listQuery: {
          startSize: 1,
          pageSize: 10,
          userId: localStorage.getItem("ID"),
        },
        batchEditForm: {pathname: '', file: {}},
        batchRestForm: {pathname: '', file: {}},
        batchCreateForm: {pathname: '', file: {}},
        afterSaleForm: {qid:'', id:''},
        exportForm: {type: 1},
        editForm: {id:0,display_identity_switch: -1, edit_permission: -1, valid_days: 0},
        formVisible: false,
        editSubjects: false,
        isAdmin: false,
        batchEditVisible: false,
        videoFlag: true,
        //上传后显示的数据
        snData: { same: [], sameData: 0, fail: [], succeed: '', all: '' },
        batchShow: false,
        batchResetVisible: false,
        exportFormVisible: false,
        editFormVisible: false,
        afterSaleVisible: false,
        batchCreateVisible: false,
        reportVisible: false,
        options: [{label:'导出未激活', value: 1}, {label: '导出体验期', value: 2}, {label: '导出过体验期未激活', value: 3}, {label: '导出已激活', value: 4}],
        resetDialogs: { show: false, deleteText: '此操作将重置qid,是否继续', id: 0 },
        activeDialogs: { show: false, deleteText: '此操作将正式激活账号,是否继续', id: 0 },
        pauseDialogs: {show: false, deleteText: '此操作将暂停激活账号,是否继续', id: 0},
        rules: {uid:[{required: true, message: '请输入旧机uid', trigger: 'blur'}]},
        reportUrl: '',
        disableEdit: false
      }
    },
    computed: {
      ...mapState({//获取上传滚动条
        goodsData: state => state.user.progress
      })
    },
    created() {
      this.colData = objectable(this.checkboxVal, this.checkboxVal); //转为数组对象，好控制table
      this.getSnQidTableData()
      const role = localStorage.getItem("roleName");
      this.isAdmin = ['超级管理员', '管理员', '代理商'].includes(role);
      this.forbid = forbid(['超级管理员', '管理员'])
    },
    methods: {
      Refresh() {
        this.listQuery = { startSize: 1, pageSize: 10, userId: localStorage.getItem("ID"), name: undefined}
        this.getSnQidTableData()
      },
      setRestId(id) {
        this.resetDialogs.show = true
        this.resetDialogs.id = id
      },
      reset() {
        let form = {
          id: this.resetDialogs.id,
          userId: localStorage.getItem("ID"),
        }
        resetQidControl(form).then(res => {
          this.$message.success(res.msg)
          this.getSnQidTableData()
        }).catch(err => {
          this.getSnQidTableData()
        })
      },
      setPauseActiveId(id) {
        this.pauseDialogs.show = true
        this.pauseDialogs.id = id
      },
      setActiveId(id) {
        this.activeDialogs.show = true
        this.activeDialogs.id = id
      },
      officialActive() {
        let form = {
          id: this.activeDialogs.id,
          userId: localStorage.getItem("ID"),
        }
        activeQidControl(form).then(res => {
          this.$message.success(res.msg)
          this.getSnQidTableData()
        }).catch(err => {
        })
      },
      toAfterSale(id) {
        this.afterSaleForm.id = id
        this.afterSaleVisible = true
      },
      afterSaleSet(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$confirm('将转移旧机qid到此设备且旧机重置为不可获取qid,是否继续?', '确认信息', {
              distinguishCancelAndClose: true,
              confirmButtonText: '确定',
              cancelButtonText: '取消'
            }).then(() => {
              let form = {
                id: this.afterSaleForm.id,
                qid: this.afterSaleForm.qid,
                userId: localStorage.getItem("ID"),
                last_ip: sessionStorage.getItem("Ip"),
              }
              afterSaleQidControl(form).then(res => {
                this.afterSaleVisible = false
                this.$message.success(res.msg)
                this.getSnQidTableData()
              }).catch(err => {
              })
            }).catch(() => {
            })
          } else {
            return false;
          }
        });
      },
      toEdit(row) {
        this.editFormVisible = true
        this.editForm.display_identity_switch = Number(row.display_identity_switch)
        this.editForm.id = row.id
        this.editForm.valid_days = row.custom_valid_days
        this.editForm.edit_permission = row.edit_permission
        let role = localStorage.getItem('roleName')
        if (row.admin_id !=  localStorage.getItem("ID") && role !== '超级管理员') {
          this.disableEdit = true
        }
        if (role === '学校') {
          this.editForm.valid_days = row.school_valid_days
        }
      },
      edit() {
        let form = {
          id: this.editForm.id,
          display_identity_switch: this.editForm.display_identity_switch,
          userId: localStorage.getItem("ID"),
          valid_days: this.editForm.valid_days,
          edit_permission: this.editForm.edit_permission
        }
        editQidControl(form).then(res => {
          this.editFormVisible = false
          this.$message.success(res.msg)
          this.getSnQidTableData()
        }).catch(err => {
        })
      },

      //批次创立更新导入模板
      handleDownload() {
        let tHeader = ["SN码"];
        let filterVal = ["sn"];
        let list = [{ "sn": 'QNS2HBYS0009'}]
        import("@/vendor/Export2Excel").then(excel => {
          const data = this.formatJson(filterVal, list);
          excel.export_json_to_excel({ header: tHeader, data, filename: '批量正式激活和重置模板' });
          this.downloadLoading = false;
        });
      },
      formatJson(filterVal, jsonData) {
        return jsonData.map(v =>
          filterVal.map(j => {
            if (j === "timestamp") {
              return parseTime(v[j]);
            } else {
              return v[j];
            }
          })
        );
      },
      batchEditClose(){
        this.$nextTick(() => {
          this.batchShow = false
          this.batchEditForm = {pathname: '', file: {}}
          this.videoFlag = true
        })
      },
      batchRestClose(){
        this.$nextTick(() => {
          this.batchShow = false
          this.batchRestForm = {pathname: '', file: {}}
          this.videoFlag = true
        })
      },
      batchCreateClose(){
        this.$nextTick(() => {
          this.batchShow = false
          this.batchCreateForm = {pathname: '', file: {}}
          this.videoFlag = true
        })
      },
      downLoadExcelUl(excelUrl) {
        let loadingInstance = Loading.service({ target: '.content2' })
        window.open('https://' + excelUrl)
        this.$nextTick(() => {
          loadingInstance.close();
        });
      },
      editFormClose() {
        this.editFormVisible = false
        this.$nextTick(() => {
          this.editForm = {display_identity_switch: -1, valid_days: 0, edit_permission: -1}
        })
      },
      exportFormClose() {
        this.exportForm = { type: 1}
      },
      afterSaleFormClose() {
        this.afterSaleVisible = false
        this.$nextTick(() => {
          this.afterSaleForm = {qid: '', id: ''}
        })
      },
      batchEditUpload(file) {
        this.batchEditForm.file = file
        this.batchEditForm.pathname = file.name
      },
      batchRestUpload(file) {
        this.batchRestForm.file = file
        this.batchRestForm.pathname = file.name
      },
      batchCreateUpload(file) {
        this.batchCreateForm.file = file
        this.batchCreateForm.pathname = file.name
      },
      submitBatchEditXlsx() {
        var fd = new FormData()
        fd.append('file', this.batchEditForm.file)
        fd.append('userId', localStorage.getItem("ID"))
        fd.append('last_ip', sessionStorage.getItem("Ip"))
        this.videoFlag = false;
        batchActiveQidControl(fd).then(res => {
          this.batchShow = true
          this.snData.sameData = res.data[1].length
          this.snData.same = JSON.parse(JSON.stringify(res.data[1]))
          this.snData.succeed = res.data.excelSuccess
          this.snData.all = res.data.total
          this.$message.success(res.msg)
          this.videoFlag = true
          this.getSnQidTableData();
        }).catch(err => {
          this.videoFlag = true;
        })
      },
      submitBatchRestXlsx() {
        var fd = new FormData()
        fd.append('file', this.batchRestForm.file)
        fd.append('userId', localStorage.getItem("ID"))
        fd.append('last_ip', sessionStorage.getItem("Ip"))
        this.videoFlag = false;
        batchResetQidControl(fd).then(res => {
          this.batchShow = true
          this.snData.sameData = res.data[1].length
          this.snData.same = JSON.parse(JSON.stringify(res.data[1]))
          this.snData.succeed = res.data.excelSuccess
          this.snData.all = res.data.total
          this.$message.success(res.msg)
          this.videoFlag = true
          this.getSnQidTableData();
        }).catch(err => {
          this.videoFlag = true;
        })
      },
      submitBatchCreateXlsx() {
        var fd = new FormData()
        fd.append('file', this.batchCreateForm.file)
        fd.append('userId', localStorage.getItem("ID"))
        fd.append('last_ip', sessionStorage.getItem("Ip"))
        this.videoFlag = false;
        batchCreateQid(fd).then(res => {
          this.batchShow = true
          this.snData.sameData = res.data[1].length
          this.snData.same = JSON.parse(JSON.stringify(res.data[1]))
          this.snData.succeed = res.data.excelSuccess
          this.snData.all = res.data.total
          this.snData.excelUrl = res.data.excelUrl
          this.$message.success(res.msg)
          this.videoFlag = true
          this.getSnQidTableData();
        }).catch(err => {
          this.videoFlag = true;
        })
      },

      //暂停正式激活
      pauseActive() {
        let form = {
          id: this.pauseDialogs.id,
          userId: localStorage.getItem("ID"),
          lastIp: localStorage.getItem("Ip"),
        }
        pauseActiveControl(form).then(res => {
          this.$message.success(res.msg)
          this.getSnQidTableData()
        }).catch(err => {
        })
      },
      //导出sn码信息
      getDownloadSn() {
        let exportForm = JSON.parse(JSON.stringify(this.exportForm))
        exportForm.userId = localStorage.getItem("ID")
        let loadingInstance = Loading.service({ target: '.content2' })
        downLoadSNQidControl(exportForm).then(res => {
          window.open('https://' + res.data.url)
          this.$nextTick(() => {
            loadingInstance.close();
          });
        }).catch(err => {
          this.$nextTick(() => {
            loadingInstance.close();
          });
          err.code == 400 ? this.$message.error(err.msg) : ''
        })
      },

      //搜索,1:课程名称
      idnameSearch() {
        if (!this.select) return this.$message.warning("请先选择查询条件");
        this.listQuery.startSize = 1
        this.listQuery.pageSize = 10
        switch (this.select) {
          case '1':
            this.listQuery.sn = this.searchTable
            this.getSnQidTableData();
            break;
          case '2':
            this.listQuery.qid = this.searchTable
            this.getSnQidTableData();
            break;
          case '3':
            this.listQuery.uid = this.searchTable
            this.getSnQidTableData();
            break;
          case '4':
            this.listQuery.username = this.searchTable
            this.getSnQidTableData();
            break;
        }
      },
      getSnQidTableData() {
        queryQidControl(this.listQuery).then(res => {
          if(res.code==200){
            this.tableData = res.data
            this.total = res.total
          }else{
            this.$message.error(this.res.msg)
          }
        }).catch(err => {
          this.tableData = []
          this.total = 0
        })
      },
      //分页
      handleSizeChange(val) {
        this.listQuery.pageSize = val
        this.getSnQidTableData()
      },
      handleCurrentChange(val) {
        this.listQuery.startSize = val
        this.getSnQidTableData()
      },
      //下拉动态table子组件
      alterCheckbok(key, conte) {
        this.key = key;
        this.colData.filter(i => {
          if (conte.indexOf(i.title) != -1) {
            i.istrue = false;
            this.$nextTick(() => {
              this.$refs.tableDataRef.doLayout();
            });
          } else {
            i.istrue = true;
            this.$nextTick(() => {
              this.$refs.tableDataRef.doLayout();
            });
          }
        });
      },
      goToGanKao(uid) {
        if (uid === 0 || uid.length <= 1) {
          this.$message.info("该学生未注册")
          return
        }
        loginGanKaoH5({
          uid: uid
        }).then(res => {
          this.reportUrl = res.data.url
          event.preventDefault()
          window.open(this.reportUrl, '_blank')
          // this.reportVisible = true
        })
      },
      downLoadData() {
        let loadingInstance = Loading.service({ target: '.content2' })
        downloadQueryData(this.listQuery).then(res => {
          window.open('https://' + res.data.url)
          this.$nextTick(() => {
            loadingInstance.close();
          });
        }).catch(err => {
          this.$nextTick(() => {
            loadingInstance.close();
          });
          err.code == 400 ? this.$message.error(err.msg) : ''
        })
      }
    }
  }
</script>

<style scoped>
/* 添加一些基本的样式 */
.modal {
  position: fixed;
  z-index: 1050;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: #fefefe;
  padding: 20px;
  border-radius: 5px;
  position: relative;
  width: 80%;
  height: 80%;
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}
</style>

